package online.flowerinsnow.minecraft.bukkit.manhunt.manager.impl;

import org.bukkit.entity.Player;
import online.flowerinsnow.minecraft.bukkit.manhunt.core.scoreboard.IPlayerScoreboard;
import online.flowerinsnow.minecraft.bukkit.manhunt.core.scoreboard.impl.PlayerScoreboardImpl;
import online.flowerinsnow.minecraft.bukkit.manhunt.manager.IScoreboardManager;

import java.util.HashMap;
import java.util.Map;

public class ScoreboardManagerImpl implements IScoreboardManager {
    private final Map<Player, IPlayerScoreboard> playerScoreboards = new HashMap<>();
    @Override
    public IPlayerScoreboard getPlayerScoreboard(Player player) {
        IPlayerScoreboard sb = playerScoreboards.get(player);
        if (sb == null) return initPlayerScoreboard(player);
        return sb;
    }

    @Override
    public IPlayerScoreboard initPlayerScoreboard(Player player) {
        IPlayerScoreboard sb = new PlayerScoreboardImpl(player);
        playerScoreboards.put(player, sb);
        return sb;
    }

    @Override
    public void unregisterPlayerScoreboard(Player player) {
        playerScoreboards.remove(player);
    }
}
